cc.Class({
    extends: cc.Component,

    properties: {
        txtMiss: [cc.Label],

        lb_phase: cc.Label,
        lb_miss: cc.Label,

    },

    onLoad () {
        this.isMissLoad = false;
        var freeScroll = this.node.getComponent('FreeScroll');
        freeScroll.loadPage = (page, items, okCbk, noCbk) => this.loadPage(page, items, okCbk, noCbk);
        freeScroll.initItem = (node, data) => this.initItem(node, data);
        freeScroll.updateItem = (item, data) => this.updateItem(item, data);
        this.initWords();
    },
    initWords: function(){
        this.lb_phase.string = LangLocal.word30;
        this.lb_miss.string = LangLocal.word28;
    },
    start() {
        this.node.getComponent('FreeScroll').initView();
    },
    
    loadPage(page, items, okCbk, noCbk) {
        cc.Linker(URLS.MotorsHistory, {
            page: page,
            pageSize: items
        }).request(okCbk, noCbk);
    },

    initItem(node, data) {
        var item = node.getComponent('HistoryItem');
        item.init(data);
        if(!this.isMissLoad) {
            this.isMissLoad = true;
            var info = data.bikeInfos;
            for(var i in info) {
                var d = info[i];
                this.txtMiss[d.bikeId - 1].string = d.miss;
            }
        }
        return item;
    },

    updateItem(item, data) {
        item.init(data);
    }
});
